/*
 * =====================================================================================
 *
 *       Filename:  acceptor.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  07/23/2012 08:47:19 PM
 *       Revision:  none
 *       Compiler:  gcc/g++
 *
 *         Author:  wangtengchao , wangtengchao AT gmail.com
 *   Organization:  
 *
 * =====================================================================================
 */

#ifndef ACCEPTOR_H
#define ACCEPTOR_H
//#include "defines.h"
#include "eventHandler.h"
#include "socket.h"

namespace inm
{
    namespace net
    {
        class Dispatcher;
        class Acceptor : public EventHandler,public boost::enable_shared_from_this<Acceptor>
        {//all connect file descriptor should be set tbo nonblock
        public:
            Acceptor(std::string name,Dispatcher* dispatcher,const InetAddr& serverAddr);
            Acceptor(std::string name,Dispatcher* dispatcher,const InetAddr& serverAddr,const NewConnectCallback& cb);
            void setNewConnectCallback(NewConnectCallback cb)
            {
                newConnectCallBack_ = cb;
            }
            void listen();
            int getSocketFdHandle() const {return listenSocket_.getSockFd();}
            //const Socket& getSocketHandle() const {return listenSocket_ ;}
            void handleRead();
            void handleClose();
        private:
            InetAddr listenAddr_;
            Socket listenSocket_;
            NewConnectCallback newConnectCallBack_;//call when accept new connection
        };
    };
};
#endif
